package com.ruoyi.project.distribute.controller;

import com.ruoyi.framework.aspectj.lang.annotation.Log;
import com.ruoyi.framework.aspectj.lang.enums.BusinessType;
import com.ruoyi.framework.web.controller.BaseController;
import com.ruoyi.framework.web.domain.AjaxResult;
import com.ruoyi.framework.web.page.TableDataInfo;
import com.ruoyi.project.distribute.domain.HosDocumentmsg;
import com.ruoyi.project.distribute.domain.HosDrug;
import com.ruoyi.project.distribute.mapper.HosDocumentmsgMapper;
import com.ruoyi.project.distribute.service.IHosDocumentmsgService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @author anran
 */
@RestController
@RequestMapping("/distribute/hosdocumentmsg")
public class HosDocumentmsgController extends BaseController
{
    @Autowired
    private IHosDocumentmsgService hosDocumentmsgService;

    /**
     * 查询单据详细信息
     */
    @GetMapping("/list")
    @PreAuthorize("@ss.hasPermi('distribute:hosdocumentmsg:list')")
    public TableDataInfo list(String documentlogId)
    {
        startPage();
        List<HosDocumentmsg> list = hosDocumentmsgService.selectHosDocumentmsgList(documentlogId);
        return getDataTable(list);
    }

    /**
     * 单据信息表添加药品信息
     */
    @GetMapping("/{drugId}/{documentlogId}")
    @PreAuthorize("@ss.hasPermi('distribute:hosdocumentmsg:list')")
    public AjaxResult getList(@PathVariable(name = "drugId") Long drugId, @PathVariable(name = "documentlogId") String documentlogId)
    {
        System.out.println("********************************"   +  drugId);
        System.out.println("********************************"   +  documentlogId);
        return toAjax(hosDocumentmsgService.insertDocumentMsgByDocumentMsgIdAndDrugId(documentlogId,drugId));
    }

    /**
     * 删除单据 药品 信息
     */
    @PreAuthorize("@ss.hasPermi('distribute:company:remove')")
    @Log(title = "单据详细信息", businessType = BusinessType.DELETE)
    @DeleteMapping("/{drugId}/{documentlogId}")
    public AjaxResult remove(@PathVariable(value = "drugId") Long drugId , @PathVariable(value = "documentlogId") String documentlogId)
    {
        return toAjax(hosDocumentmsgService.deleteHosDocumentMsgByDocumentMsgIdAndDrugId(documentlogId, drugId));
    }


}
